﻿@model Projectmanagement.Models._Motorcade
<script type="text/javascript">
    var fileName = "";

    function UploadProfileImage_OnUpload(e) {
        var id = $("#ID").val();
        var files = e.files;
        $.each(files, function () {
            fileName = this.name + ',' + fileName;
        });
        $("#MotorcadeFileId").val(fileName);
        e.data = { strImageName: fileName };
    }
    
   
</script>
<fieldset>
    <legend>车队</legend>

<table class="noline" style="line-height: 30px; border:1px solid #eee; margin-top:10px;">
    
    <tr style="line-height: 1px; background:#f1f1f1">
            <td colspan="8">
                <p style="font-weight: bolder">
                    联系人</p>
            </td>
        </tr>
        <tr><td colspan="8" style="height:10px;"></td></tr>
    <tr>
        <td align="right"  style="width: 150px;">
            @Html.LabelFor(x => x.ComyanyName):
        </td>
        <td>
            @Html.TextBoxFor(x => x.ComyanyName, new { style = "width:165px;" })<br />
            @Html.ValidationMessageFor(x => x.ComyanyName)
        </td>
        <td align="right">
            @Html.LabelFor(x => x.TravelName):
        </td>
        <td>
            @Html.TextBoxFor(x => x.TravelName, new { style = "width:165px;" })<br />
            @Html.ValidationMessageFor(x => x.TravelName)
        </td>
        <td align="right">@Html.LabelFor(x => x.TravelWay):
        </td>
        <td>
            @Html.TextBoxFor(x => x.TravelWay, new { style = "width:165px;" })<br />
        </td>
        <td colspan="2">&nbsp;</td>
    </tr>
    <tr>
        <td align="right">
            @Html.LabelFor(x => x.MotorcycleType):
        </td>
        <td>
            @Html.TextBoxFor(x => x.MotorcycleType, new { style = "width:165px;" })<br />
            @Html.ValidationMessageFor(x => x.MotorcycleType)
        </td>
        <td align="right" id="MotorcyclePrice">@Html.LabelFor(x => x.MotorcyclePrice):
        </td>
        <td>
            @Html.TextBoxFor(x => x.MotorcyclePrice, new { style = "width:165px;" })<br />
        </td>
        <td align="right">@Html.LabelFor(x => x.City):
        </td>
        <td>
            @Html.DropDownListFor(x => x.City, Model.GetCitySelectListItems(), "请选择......", new { style = "width:165px;" })
        </td>
        <td colspan="2">&nbsp;</td>
    </tr>
    <tr>
        <td align="right">@Html.LabelFor(x => x.TravelOtherWay):
        </td>
        <td>
            @Html.TextBoxFor(x => x.TravelOtherWay, new { style = "width:165px;" })<br />
            @Html.ValidationMessageFor(x => x.TravelOtherWay)
        </td>
        <td colspan="6">&nbsp;</td>
    </tr>
    <tr><td colspan="8" style="height:10px;">&nbsp;</td></tr>
    <tr>
        <td align="right">
            <label>文件/图片上传:</label>
        </td>
        <td colspan="7">
            @Html.HiddenFor(m => m.MotorcadeFileId)
            @Html.HiddenFor(m => m.ID)
            @(Html.Telerik().Upload()
                .Name("attachments")
        .Multiple((bool)ViewData["multiple"])
        .Async(async => async
                                    .Save("SaveMotorcadeFile", "Motorcade", new { strImageName = Model.MotorcadeFileId })
                                            .Remove("RemoveMotorcadeFile", "Motorcade")
            .AutoUpload((bool)ViewData["autoUpload"])

        )
                .ClientEvents(events => events.OnUpload("UploadProfileImage_OnUpload").OnComplete("OnComplete"))
)
        </td>
    </tr>
    <tr>
        <td align="right"><label>文件/图片下载:</label>
        </td>
        <td colspan="7">
            <div id="filelist">
                <ul id="filelist_file">
                </ul>
                <ul id="filelist_img">
                </ul>
            </div>
        </td>
    </tr>
    <tr>
        <td align="right" style="vertical-align:top">@Html.LabelFor(x => x.MotorcycleDesc):
        </td>
        <td colspan="7">
            @Html.TextAreaFor(x => x.MotorcycleDesc, new { rows = "1", style="width:86%"})<br />
            @Html.ValidationMessageFor(x => x.MotorcycleDesc)
        </td>
    </tr>
</table>
@Html.Telerik().Window().Name("showImage").Title("显示图片").Content(
@<text>
<div id="ImgField">
</div>
</text>
    ).Visible(false).Resizable().Width(600).Height(480)
</fieldset>
<script type="text/javascript">
    var count = 0;
    function getFile() {

        var id = $("#ID").val();
        var url = "/Motorcade/GetFile/";
        $.post(url, { 'ID': id }, function (data) {
            $.each(data, function (i, item) {
                var result = /\.[^\.]+/.exec(item.FileName);
                if (result != ".jpg" && result != ".png" && result && ".jpeg" && result != ".gif") {
                    $("#filelist_file").append(
                    '<li id=tf-' + item.ID + '>' +
                    '<a href=' + item.FileUrl + ' target="_blank">' + item.FileName + '</a>' +
                    '<a href="javascript:;" onclick="deletetaskfile(' + item.ID + ')">删除</a>' +
                    '</li>');
                }
                else {
                    $("#filelist_img").append(
                    '<li id=tf-' + item.ID + '>' +
                    '<img  width="100px" height="60px"  src=' + item.FileUrl + ' />' +
                    '<a href=' + item.FileUrl + ' target="_blank">' + item.FileName + '</a>' +
                    '<a href="javascript:;" onclick="deletetaskfile(' + item.ID + ')">删除</a>' +
                    '</li>');
                }
            });

        });

    }

    (function () {
        if ((document.readyState && document.readyState == 'complete' && $("#ID").val() != "0") || count == 5) {
            var id = $("#ID").val();
            getFile();
        } else {
            count++;
            setTimeout(arguments.callee, 10);
        }
    })();

    function deletetaskfile(id) {
        var name = $("#tf-" + id).find("a").eq(0).text();
        if (confirm("确定将" + name + "删除吗")) {
            $.ajax({
                url: "/Motorcade/deletefile/" + id,
                type: "post",
                dataType: "json",
                success: function (data, status) {
                    if (data == "OK") {
                        $("#tf-" + id).remove();
                    }
                }
            });
        }
    }
    function showImageWindow(e) {
        $("#ImgField").empty();
        var url = $("#" + e).attr("src");
        var window = $("#showImage").data("tWindow");
        $("#ImgField").append("<img  alt='' id=" + e + " src=" + url + " />");
        window.center().open();
    }
</script>
<style>
    .t-upload
    {
        float: left;
    }
    
    .note
    {
        clear: left;
        float: left;
    }
    .noline
    {
        width: 1250px;
    }
    .noline, .noline tr, .noline td
    {
        border: 0;
        padding: 2px;
    }
    .tableTd
    {
        width: 120px;
        float: left;
        text-align: left;
    }
    #filelist_file
    {
        clear: both;
        display: inline-block;
        width: 1071px;
    }
    #filelist_img
    {
        clear: both;
        display: inline-block;
        padding-top: 15px;
        margin-top: 5px;
        width: 1071px;
        border-top: 1px dotted #eee;
    }
    #filelist_file li
    {
        width: 357px;
        height: 28px;
        float: left;
    }
    #filelist_img li
    {
        width: 357px;
        float: left;
    }
</style>
